//获取应用实例
const app = getApp();

Page({
  /**
   * 页面的初始数据
   */
  data: {

    orderList4: [],
    orderList4isNull: false,
    page: 1,
    size: 30,
    hasMoreData: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function() {

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    // 页面渲染完成
    this.getDeviceInfo();
  },

  onShow: function() {
    var that = this;
    that.onPullDownRefresh();
  },

  getDeviceInfo: function() {
    let that = this
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          deviceW: res.windowWidth,
          deviceH: res.windowHeight
        })
      }
    })
  },



  //待评价
  getOrder4: function() {
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    var that = this;
    // that.data.orderList4 = [];
    wx.request({
      url: app.globalData.api + '/app.php?c=Order&a=getOrderList',
      data: {
        token: app.globalData.token,
        p: that.data.page,
        per: that.data.size,
        status: '4',
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success(res) {
        console.log(res)
        wx.hideLoading();
        wx.stopPullDownRefresh();
        if (res.data.code == 0) {
          var contentlistTem = res.data.data.list;
          for (var i = 0; i < res.data.data.list.length; i++) {
            console.log(res.data.data.list[i].detail.length)
            if (res.data.data.list[i].detail.length > 0) {
              // if (res.data.data.list[i].detail[0].status == 4) {
              res.data.data.list[i].detail[0].img = app.globalData.imgUrl + "" + res.data.data.list[i].detail[0].img;
              that.setData({
                orderList4: that.data.orderList4.concat(res.data.data.list[i])
              })

              // }
            }
          }
          if (that.data.orderList4.length > 0) {
            if (contentlistTem.length < that.data.size) {
              that.setData({
                hasMoreData: false
              })
            } else {
              that.setData({
                hasMoreData: true
              })
            }
            that.setData({
              orderList4isNull: false
            })
          } else {
            that.setData({
              orderList4isNull: true
            })
          }
        } else {
          wx.showToast({
            title: "" + res.data.msg,
            icon: 'none'
          })
        }

      }
    })
  },

  comment: function(e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/mine/order-detail-3?order_id=' + id,
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.setData({
      page: 1,
      orderList4:[],
    })
    this.getOrder4();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    this.setData({
      page: this.data.page + 1
    })
    this.getOrder4();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
});